package com.skywolf.chem.riding.service.impl;

import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.riding.entity.Info;
import com.skywolf.chem.riding.mapper.InfoMapper;
import com.skywolf.chem.riding.pojo.RidingQueryDto;
import com.skywolf.chem.riding.pojo.RidingQueryParam;
import com.skywolf.chem.riding.service.IInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 骑行表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-09-07
 */
@Service
public class InfoServiceImpl extends ServiceImpl<InfoMapper, Info> implements IInfoService {

    @Autowired
    InfoMapper infoMapper;


    @Override
    public int updateRiding(Long uid, Double num,Integer updateType) {
        return infoMapper.updateRiding(uid,num,new Date(),updateType);
    }

    @Override
    public int getPaiMing(Double num) {
        return infoMapper.getPaiMing(num);
    }

    @Override
    public PageVO<RidingQueryDto> pageList(RidingQueryParam queryParam) {
        Long startNum = queryParam.getPageSize()*(queryParam.getPageNum()-1);
        Long endNum = queryParam.getPageSize();
        Integer count = infoMapper.getPageCount(null,null,queryParam.getCity());
        List<RidingQueryDto> list = infoMapper.getPageList(null,null,startNum,endNum,queryParam.getQueryType(),queryParam.getCity());
        PageVO<RidingQueryDto> pageVO = new PageVO<>();
        pageVO.setList(list);
        pageVO.setTotal(Long.valueOf(count));
        pageVO.setPageSize(queryParam.getPageSize());
        pageVO.setPageNum(queryParam.getPageNum());
        Long totalPage = (count/queryParam.getPageSize())+(count%queryParam.getPageSize()>0?1:0);
        if(totalPage.equals(0)){
            totalPage = queryParam.getPageNum();
        }
        pageVO.setPages(totalPage);
        return pageVO;
    }

    @Override
    public PageVO<RidingQueryDto> managerPageList(RidingQueryParam queryParam) {
        Long startNum = queryParam.getPageSize()*(queryParam.getPageNum()-1);
        Long endNum = queryParam.getPageSize();
        Integer count = infoMapper.getPageCount(queryParam.getStartTime(),queryParam.getEndTime(),queryParam.getCity());
        List<RidingQueryDto> list = infoMapper.getPageList(queryParam.getStartTime(),queryParam.getEndTime(),startNum,endNum,queryParam.getQueryType(),queryParam.getCity());
        PageVO<RidingQueryDto> pageVO = new PageVO<>();
        pageVO.setList(list);
        pageVO.setTotal(Long.valueOf(count));
        pageVO.setPageSize(queryParam.getPageSize());
        pageVO.setPageNum(queryParam.getPageNum());
        Long totalPage = (count/queryParam.getPageSize())+(count%queryParam.getPageSize()>0?1:0);
        if(totalPage.equals(0)){
            totalPage = queryParam.getPageNum();
        }
        pageVO.setPages(totalPage);
        return pageVO;
    }

    @Override
    public Long getMaxId() {
        return infoMapper.getMaxId();
    }

    @Override
    public List<LocalDateTime> getLocalDateTime() {
        return infoMapper.getLocalDateTime();
    }

    @Override
    public void addRiding(Info info) {
        infoMapper.addRiding(info);
    }


}
